package cyx.example.ddd.domain.shared;

import lombok.Getter;
import lombok.Setter;

/**
 * 实体基类
 * 实体类都应该继承此类
 */
@Getter
@Setter
public abstract class Entity<ID> {
    private ID id;

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null || getClass() != obj.getClass())
            return false;
        Entity<?> entity = (Entity<?>) obj;
        return id != null && id.equals(entity.getId());
    }

    @Override
    public int hashCode() {
        return id != null ? id.hashCode() : 0;
    }
}